package org.erp.procurement.controller;

import lombok.AllArgsConstructor;
import lombok.extern.log4j.Log4j2;
import org.erp.common.domain.Result;
import org.erp.common.page.DataPageResp;
import org.erp.common.page.PageQueryModel;
import org.erp.procurement.convert.PcOrderConvert;
import org.erp.procurement.entity.bo.OrderUpdateBo;
import org.erp.procurement.entity.bo.PcOrderAddBo;
import org.erp.procurement.entity.bo.PcOrderQueryBo;
import org.erp.procurement.entity.vo.PcOrderVo;
import org.erp.procurement.service.PcOrderService;
import org.springframework.web.bind.annotation.*;

import static org.erp.common.domain.Result.success;

/**
 * 采购订单控制层
 *
 * @author libin
 * @version 1.0
 * @description: 采购订单控制层
 * @date 2025/11/5 11:00
 **/
@Log4j2
@RestController
@AllArgsConstructor
@RequestMapping("/pc/order")
public class PcOrderController {

    private final PcOrderService pcOrderService;

    private final PcOrderConvert pcOrderConvert;


    @PostMapping("/list")
    public Result<DataPageResp<PcOrderVo>> pcPageList(@RequestBody PcOrderQueryBo pcOrderQueryBo) {
        PageQueryModel<PcOrderVo> queryModel = pcOrderService.pcPageList(pcOrderConvert.boConvertDto(pcOrderQueryBo));
        return success(DataPageResp.of(queryModel.getTotal(), queryModel.getDataList()));
    }

    /**
     * 线下采购订单添加
     *
     * @param pcOrderAddBo
     * @return
     */
    @PostMapping("/save")
    public Result<String> pcSave(@RequestBody PcOrderAddBo pcOrderAddBo) {
        pcOrderService.pcSave(pcOrderAddBo);
        return success();
    }


    /**
     * 修改采购数量
     *
     * @param orderUpdateBo
     * @return
     */
    @PutMapping("/update")
    public Result<String> updatePurchaseQuantity(@RequestBody OrderUpdateBo orderUpdateBo) {
        pcOrderService.updatePurchaseQuantity(orderUpdateBo);
        return success();
    }
}
